<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card>
        <el-tabs>
          <el-tab-pane label="登录账户设置">

            <!-- 放置表单 -->
            <el-form ref="formData" :model="formData" :rules="rules" label-width="120px" style="margin-left: 120px; margin-top:30px">
              <el-form-item label="姓名:" prop="username">
                <el-input v-model="formData.username" style="width:300px" />
              </el-form-item>
              <el-form-item label="密码:" prop="password2">
                <el-input v-model="formData.password2" style="width:300px" type="password" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="saveUserDetailById">更新</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="个人详情">
            <userInfo />
          </el-tab-pane>
          <el-tab-pane label="岗位信息">
            <jobInfo />
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
  </div>
</template>

<script>
import { getUserDetailById, saveUserDetailById } from '@/api/employeeSimple'
import userInfo from './components/user-info'
import jobInfo from './components/job-info'
export default {
  components: {
    userInfo, jobInfo
  },
  data() {
    return {
      formData: {
        username: '',
        password2: ''
      },
      rules: {
        username: [
          { required: true, message: '数据不能为空', trigger: 'blur' },
          { min: 1, max: 4, message: '2-4个字之间', trigger: 'blur' }
        ],
        password2: [
          { required: true, message: '数据不能为空', trigger: 'blur' },
          { min: 6, max: 16, message: '6-16个字之间', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.getUserDetailById()
  },
  // 获取用户信息 回显
  methods: {
    async getUserDetailById() {
      this.formData = await getUserDetailById(this.$route.params.id)
    },
    async saveUserDetailById() {
      // 校验表单
      await this.$refs.formData.validate()
      // 发送修改请求
      await saveUserDetailById({ ...this.formData, password: this.formData.password2 })
      // 提示发送成功
      this.$message.success('操作成功')
    }
  }
}
</script>

<style>

</style>
